package com.wwb.w0518;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.viewpager.widget.ViewPager;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.ImageView;

import com.wwb.w0518.adapter.MyFragAdapter;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    ViewPager viewPager;
    FragmentManager fm;
    List<Fragment> fragmentList;
    ImageView img1,img2,img3;
    List<ImageView> imageViewList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        String number="20191415123";
        String name="武文博";

        viewPager=findViewById(R.id.viewpagerdemo);
        fm=getSupportFragmentManager();
        fragmentList=new ArrayList<>();
        fragmentList.add(new Page1Frag());
        fragmentList.add(new Page2Frag());
        fragmentList.add(new Page3Frag());
        viewPager.setAdapter(new MyFragAdapter(fm,0,fragmentList));

        img1=findViewById(R.id.img1);
        img2=findViewById(R.id.img2);
        img3=findViewById(R.id.img3);
        //img1.setBackgroundColor(Color.parseColor("#d5ebe1"));

        imageViewList=new ArrayList<>();
        imageViewList.add(img1);
        imageViewList.add(img2);
        imageViewList.add(img3);
       // Bitmap bitmap=WatermarkSettings.createWatermark()
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener(){

            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                cleanback();
                imageViewList.get(position).setBackgroundColor(Color.parseColor("#d5ebe1"));

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }
    public void cleanback(){
        img1.setBackgroundColor(Color.WHITE);
        img2.setBackgroundColor(Color.WHITE);
        img3.setBackgroundColor(Color.WHITE);
    }
}